﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DXApplicationTangche.UC.流程.条码整体信息;
using DXApplicationTangche.UC.标签打印;
using DXApplicationTangche.UC.订单一览新.订单预览新.service;
using Seagull.BarTender.Print;
using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.UC.流程.Service;
using DXApplicationTangche.UC.流程.库存界面;
using static DXApplicationTangche.UC.门店下单.form.Frm订单一览;
using DXApplicationTangche.model;
using DXApplicationTangche.UC.订单一览新.订单预览新;
using DXApplicationTangche.UC.样品管理.样品订单预览;

namespace DXApplicationTangche.UC.流程
{
    public partial class Form库存界面 : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        private OrderCommitDTO返回 OrderCommitDTO返回 = new OrderCommitDTO返回();
        private List<BarcodeStoreInfoDTO> barcodeStoreInfoDTOs = new List<BarcodeStoreInfoDTO>();
        private String batchNo { get; set; }
        private String salesType { get; set; }

        private String styleId = "";
        private String orderId = "";
        private Enum订单类别 enum订单类别 = Enum订单类别.销售订单;
        public Form库存界面()
        {
            InitializeComponent();
            //this.initPanel(new Form库存界面详情());
            this.initPanel(new Form库存发运界面());
            this.barcodeStoreInfoDTOs = 库存Service.getBarcodeStoreInfo();
            this.gridControl库存一览.DataSource = this.barcodeStoreInfoDTOs;
        }
        private void initPanel(Form frm)
        {
            this.splitContainer左右.Panel2.Controls.Clear();
            //指示窗体显示是否为顶级窗口
            frm.TopLevel = false;
            this.splitContainer左右.Panel2.Controls.Add(frm);
            frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frm.Dock = System.Windows.Forms.DockStyle.Fill;
            frm.Show();
        }

        private void barButtonItem打印发货贴_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //当批号不为空，传批号
            if (!String.IsNullOrWhiteSpace(this.batchNo))
            {
                new Form发货贴带详情(this.batchNo,this.salesType).ShowDialog();
            }
            else
            {
                new Form发货贴带详情().ShowDialog();
            }
        }

        private void gridView库存一览_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            String barcode = FunctionHelper.GetgridViewValue(this.gridView库存一览, this.gridView库存一览.FocusedRowHandle, "barcode");
            String urgentFlg = FunctionHelper.GetgridViewValue(this.gridView库存一览, this.gridView库存一览.FocusedRowHandle, "urgentFlg");
            String mobile = FunctionHelper.GetgridViewValue(this.gridView库存一览, this.gridView库存一览.FocusedRowHandle, "mobile");
            this.batchNo = FunctionHelper.GetgridViewValue(this.gridView库存一览, this.gridView库存一览.FocusedRowHandle, "batchNo");
            this.salesType = FunctionHelper.GetgridViewValue(this.gridView库存一览, this.gridView库存一览.FocusedRowHandle, "salesType");
            this.initPanel(new Form库存发运界面(barcode,urgentFlg,mobile));
        }

        private void barButtonItem包装贴_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            new Form包装码().ShowDialog();
        }

        private void gridView库存一览_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            if (e.Column.Name.Equals("gridColumn尺码"))
            {
                if (!String.IsNullOrWhiteSpace(e.DisplayText))
                {
                    try { e.DisplayText = e.DisplayText.Replace("IGS_GROUP_SIZE-", "").Replace("EGS_GROUP_SIZE-", ""); } catch { }
                }
            }
        }

        private void barButtonItem打印订单纸_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            String batchNo = FunctionHelper.GetgridViewValue(this.gridView库存一览, this.gridView库存一览.FocusedRowHandle, "batchNo");
            if (String.IsNullOrEmpty(batchNo))
            {
                MessageBox.Show("生产批号不能为空");
                return;
            }
            this.OrderCommitDTO返回 = 订单预览新Service.get订单预览By批号(batchNo);
            if (!String.IsNullOrWhiteSpace(this.OrderCommitDTO返回.orderId))
            {
                //  全局变量赋值            
                this.orderId = this.OrderCommitDTO返回.orderId;
                if (this.enum订单类别 == Enum订单类别.销售订单)
                {
                    new Form订单预览新(this.orderId).ShowDialog();
                }
                else if (this.enum订单类别 == Enum订单类别.样品订单)
                {
                    new Form样品订单预览新(this.orderId).ShowDialog();
                }
                else
                {
                    new Form订单预览新(this.orderId).ShowDialog();
                }
            }
            else
            {
                MessageBox.Show("成衣条码有误");
                return;
            }
        }

        private void simpleButton刷新_Click(object sender, EventArgs e)
        {
            this.barcodeStoreInfoDTOs = 库存Service.getBarcodeStoreInfo();
            this.gridControl库存一览.DataSource = this.barcodeStoreInfoDTOs;
        }

        private void barButtonItem导出excel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Title = "导出Excel";
            fileDialog.Filter = "Excel文件(*.xls)|*.xls";
            DialogResult dialogResult = fileDialog.ShowDialog(this);
            if (dialogResult == DialogResult.OK)
            {
                DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
                this.gridControl库存一览.ExportToXls(fileDialog.FileName);
                DevExpress.XtraEditors.XtraMessageBox.Show("保存成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }
}